// 专门处理请求

import http from './http.js'
import api from './api.js'

// 注册请求
export function register(data) {
    return http({
        method:'POST',
        url:api.register,
        data:data
    })
}
// 登录请求
export function login(data) {
    return http({
        method:'POST',
        url:api.login,
        data:data
    })
}
// 退出
export function logout() {
    return http({
        method:'POST',
        url:api.logout,
    })
}
// 获取自己用户信息
export function getUser() {
    return http({
        method:'GET',
        url:api.getUser,
    })
}

// 获取轮播图
export function getCarousel(index) {
    return http({
        methods:'GET',
        url:api.getCarousel,
        params:{
            site:index,
            project_id:26,
        }
    })
}

// 获取商品信息
// 获取所有商品
export function getGoods(num) {
    return http({
        methods:'GET',
        url:api.getGoods,
        params:{
            page:1,
            limit: num,
            project_id:26,
        }
    })
}
// 获取一类商品
export function getClassifyGoods(num,classifyId) {
    return http({
        methods:'GET',
        url:api.getGoods,
        params:{
            page:1,
            limit: num,
            project_id:26,
            classify_id:classifyId
        }
    })
}
// 获取单个商品
export function getSingleGood(id) {
    return http({
        methods:'GET',
        url:api.getGoods + `${id}`,
    })
}
// 搜索商品
export function searchGood(name) {
    return http({
        methods:'GET',
        url:api.getGoods,
        params:{
            name:name,
            project_id:26
        }
    })
}

// 添加购物车
export function addCart(data) {
    // console.log('fff')
    return http({
        method:'POST',
        url:api.addCart,
        data:data
    })
}
// 获取购物车列表信息
export function getCart() {
    return http({
        method:'GET',
        url:api.getCart,
        params:{
            project_id:26
        }
    })
}
// 更新单条购物车数据
export function updateCart(id,data) {
    return http({
        method:'PUT',
        url:api.updateCart + `${id}`,
        data:data
    })
}
// 删除购物车
export function deleteCart(id) {
    return http({
        method:'DELETE',
        url:api.deleteCart + `${id}`,
    })
}

// 获取城市
export function getCity() {
    return http({
        method:'GET',
        url:api.getCity,
    })
}
// 添加地址
export function addAddress(data) {
    return http({
        method:'POST',
        url:api.addAddress,
        data:data,
    })
}
// 修改地址
export function setAddress(id,data) {
    return http({
        method:'PUT',
        url:api.setAddress + `${id}`,
        data:data,
    })
}
// 删除地址
export function delAddress(id) {
    return http({
        method:'DELETE',
        url:api.delAddress + `${id}`,
    })
}
// 获取地址列表
export function getAddressList() {
    return http({
        method:'GET',
        url:api.getAddressList,
    })
}
// 设置默认地址
export function setDefaultAddress(id) {
    return http({
        method:'POST',
        url:api.setDefaultAddress + `${id}`,
    })
}
// 获取默认地址
export function getDefaultAddress() {
    return http({
        method:'GET',
        url:api.getDefaultAddress,
    })
}
// 添加订单
export function addOrder(data) {
    return http({
        method:'POST',
        url:api.orderInfo,
        data:data
    })
}
// 获取单条订单信息
export function getOrder(id) {
    return http({
        method:'GET',
        url:api.orderInfo + `${id}`,
    })
}
// 获取订单列表
export function getOrderList() {
    return http({
        method:'GET',
        url:api.orderInfo,
        params:{
            project_id:26,
        }
    })
}
// 更新订单信息
export function setOrder(id,data) {
    return http({
        method:'PUT',
        url:api.orderInfo + `${id}`,
        data:data
    })
}
// 删除订单
export function delOrder(id) {
    return http({
        method:'DELETE',
        url:api.orderInfo + `${id}`,
    })
}



